import http from "@/api";
import { ResPage, OrgManager } from "@/api/interface/index";
import qs from "qs";
/**
 * @name 系统工具模块
 */

// 获取通知规则
export const findPagerNoticeRule = () => {
  return http.get(`/pages/noticeRule!findPager.action`, {}, { cancel: false });
};

// 更新通知规则
export const noticeRuleUpdate = (params: any[]) => {
  let newobj = {};
  params.forEach(param => {
    Object.keys(param).forEach(key => {
      // let newParams = JSON.parse(JSON.stringify(res));
      if (`${key}` == "noticeRuleNo") {
        newobj["noticeRuleNos['" + `${param[key]}` + "']"] = `${param[key]}`;
      }
      if (`${key}` == "useStatus") {
        if (`${param[key]}`.toString() == "true") {
          newobj["useStatuses['" + param["noticeRuleNo"] + "']"] = true;
        }
      }
    });
  });
  return http.post(`/pages/noticeRule!noticeRuleUpdate.action`, qs.stringify(newobj));
};

// 获取门户面板配置页面
export const portalDashboardPreview = () => {
  return http.post<String>(
    `/pages/userCustom!portalDashboardPreview.action?queryDTO.customType=1&queryDTO.loginName=admin2`,
    qs.stringify({})
  ); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};

/**
 * @name 查询定期任务
 */
// 查询定期任务
export const findPageScheduledTask = (params: {}, header: string, unhandle: string[]) => {
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      if (unhandle.length > 0) {
        if (unhandle.includes(`${key}`)) {
          newobj[`${key}`] = `${params[key]}`;
        } else {
          newobj[header + "." + `${key}`] = `${params[key]}`;
        }
      } else {
        newobj[header + "." + `${key}`] = `${params[key]}`;
      }
    });
  } else {
    newobj = params;
  }
  return http.postitsm<string>(
    `/pages/scheduledTask!findPageScheduledTask.action?queryDTO.scheduledTaskId=`,
    qs.stringify(newobj)
  );
};

// 保存定时任务
export const saveScheduledTask = (params: {}, header: string, idsStr: string) => {
  let newobj = {};
  let weekWeeksStr = "";
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      if (`${key}` === "companyNo") {
        newobj[header + ".requestDTO." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "etitle") {
        newobj[header + ".requestDTO." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "formId") {
        newobj[header + ".requestDTO." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "companyName") {
        newobj[header + ".requestDTO." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "createdByNo") {
        newobj[header + ".requestDTO." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "createdByName") {
        newobj[header + ".requestDTO." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "requestCategoryName") {
        newobj[header + ".requestDTO." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "requestCategoryNo") {
        newobj[header + ".requestDTO." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "edesc") {
        newobj[header + ".requestDTO." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "imodeNo") {
        newobj[header + ".requestDTO." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "priorityNo") {
        newobj[header + ".requestDTO." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "effectRangeNo") {
        newobj[header + ".requestDTO." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "levelNo") {
        newobj[header + ".requestDTO." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "seriousnessNo") {
        newobj[header + ".requestDTO." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "locationName") {
        newobj[header + ".requestDTO." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "locationNos") {
        newobj[header + ".requestDTO." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "attachmentStr") {
        newobj[header + ".requestDTO." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "serviceDirNos") {
        newobj[`${key}`] = `${params[key]}`;
      } else if (`${key}` === "MON" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".weekWeeks=MON";
        } else {
          weekWeeksStr += "&" + header + ".weekWeeks=MON";
        }
      } else if (`${key}` === "TUE" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".weekWeeks=TUE";
        } else {
          weekWeeksStr += "&" + header + ".weekWeeks=TUE";
        }
      } else if (`${key}` === "WED" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".weekWeeks=WED";
        } else {
          weekWeeksStr += "&" + header + ".weekWeeks=WED";
        }
      } else if (`${key}` === "THU" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".weekWeeks=THU";
        } else {
          weekWeeksStr += "&" + header + ".weekWeeks=THU";
        }
      } else if (`${key}` === "FRI" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".weekWeeks=FRI";
        } else {
          weekWeeksStr += "&" + header + ".weekWeeks=FRI";
        }
      } else if (`${key}` === "SAT" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".weekWeeks=SAT";
        } else {
          weekWeeksStr += "&" + header + ".weekWeeks=SAT";
        }
      } else if (`${key}` === "SUN" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".weekWeeks=SUN";
        } else {
          weekWeeksStr += "&" + header + ".weekWeeks=SUN";
        }
      } else if (`${key}` === "JAN" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".monthMonths=JAN";
        } else {
          weekWeeksStr += "&" + header + ".monthMonths=JAN";
        }
      } else if (`${key}` === "FEB" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".monthMonths=FEB";
        } else {
          weekWeeksStr += "&" + header + ".monthMonths=FEB";
        }
      } else if (`${key}` === "MAR" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".monthMonths=MAR";
        } else {
          weekWeeksStr += "&" + header + ".monthMonths=MAR";
        }
      } else if (`${key}` === "APR" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".monthMonths=APR";
        } else {
          weekWeeksStr += "&" + header + ".monthMonths=APR";
        }
      } else if (`${key}` === "MAY" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".monthMonths=MAY";
        } else {
          weekWeeksStr += "&" + header + ".monthMonths=MAY";
        }
      } else if (`${key}` === "JUN" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".monthMonths=JUN";
        } else {
          weekWeeksStr += "&" + header + ".monthMonths=JUN";
        }
      } else if (`${key}` === "JUL" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".monthMonths=JUL";
        } else {
          weekWeeksStr += "&" + header + ".monthMonths=JUL";
        }
      } else if (`${key}` === "AUG" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".monthMonths=AUG";
        } else {
          weekWeeksStr += "&" + header + ".monthMonths=AUG";
        }
      } else if (`${key}` === "SEP" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".monthMonths=SEP";
        } else {
          weekWeeksStr += "&" + header + ".monthMonths=SEP";
        }
      } else if (`${key}` === "OCT" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".monthMonths=OCT";
        } else {
          weekWeeksStr += "&" + header + ".monthMonths=OCT";
        }
      } else if (`${key}` === "NOV" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".monthMonths=NOV";
        } else {
          weekWeeksStr += "&" + header + ".monthMonths=NOV";
        }
      } else if (`${key}` === "DEC" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".monthMonths=DEC";
        } else {
          weekWeeksStr += "&" + header + ".monthMonths=DEC";
        }
      } else {
        if (`${params[key]}`.toString() === "false") {
          console.log("vvvvvvvvvv");
        } else {
          console.log(`${params[key]}`);
          console.log(`${params[key]}`.toString() === "false");
          newobj[header + "." + `${key}`] = `${params[key]}`;
        }
      }
    });
  }
  if (weekWeeksStr == "") {
    weekWeeksStr = "?" + idsStr;
  } else {
    weekWeeksStr += "&" + idsStr;
  }
  return http.post(`/pages/scheduledTask!saveScheduledTask.action` + weekWeeksStr, qs.stringify(newobj));
};

// 编辑定时任务
export const editScheduledTask = (params: {}, header: string, idsStr: string) => {
  let newobj = {};
  let weekWeeksStr = "";
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      if (`${key}` === "companyNo") {
        newobj[header + ".requestDTO." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "etitle") {
        newobj[header + ".requestDTO." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "formId") {
        newobj[header + ".requestDTO." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "companyName") {
        newobj[header + ".requestDTO." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "createdByNo") {
        newobj[header + ".requestDTO." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "createdByName") {
        newobj[header + ".requestDTO." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "requestCategoryName") {
        newobj[header + ".requestDTO." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "requestCategoryNo") {
        newobj[header + ".requestDTO." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "edesc") {
        newobj[header + ".requestDTO." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "imodeNo") {
        newobj[header + ".requestDTO." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "priorityNo") {
        newobj[header + ".requestDTO." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "effectRangeNo") {
        newobj[header + ".requestDTO." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "levelNo") {
        newobj[header + ".requestDTO." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "seriousnessNo") {
        newobj[header + ".requestDTO." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "locationName") {
        newobj[header + ".requestDTO." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "locationNos") {
        newobj[header + ".requestDTO." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "attachmentStr") {
        newobj[header + ".requestDTO." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "serviceDirNos") {
        newobj[`${key}`] = `${params[key]}`;
      } else if (`${key}` === "MON" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".weekWeeks=MON";
        } else {
          weekWeeksStr += "&" + header + ".weekWeeks=MON";
        }
      } else if (`${key}` === "TUE" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".weekWeeks=TUE";
        } else {
          weekWeeksStr += "&" + header + ".weekWeeks=TUE";
        }
      } else if (`${key}` === "WED" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".weekWeeks=WED";
        } else {
          weekWeeksStr += "&" + header + ".weekWeeks=WED";
        }
      } else if (`${key}` === "THU" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".weekWeeks=THU";
        } else {
          weekWeeksStr += "&" + header + ".weekWeeks=THU";
        }
      } else if (`${key}` === "FRI" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".weekWeeks=FRI";
        } else {
          weekWeeksStr += "&" + header + ".weekWeeks=FRI";
        }
      } else if (`${key}` === "SAT" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".weekWeeks=SAT";
        } else {
          weekWeeksStr += "&" + header + ".weekWeeks=SAT";
        }
      } else if (`${key}` === "SUN" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".weekWeeks=SUN";
        } else {
          weekWeeksStr += "&" + header + ".weekWeeks=SUN";
        }
      } else if (`${key}` === "JAN" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".monthMonths=JAN";
        } else {
          weekWeeksStr += "&" + header + ".monthMonths=JAN";
        }
      } else if (`${key}` === "FEB" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".monthMonths=FEB";
        } else {
          weekWeeksStr += "&" + header + ".monthMonths=FEB";
        }
      } else if (`${key}` === "MAR" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".monthMonths=MAR";
        } else {
          weekWeeksStr += "&" + header + ".monthMonths=MAR";
        }
      } else if (`${key}` === "APR" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".monthMonths=APR";
        } else {
          weekWeeksStr += "&" + header + ".monthMonths=APR";
        }
      } else if (`${key}` === "MAY" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".monthMonths=MAY";
        } else {
          weekWeeksStr += "&" + header + ".monthMonths=MAY";
        }
      } else if (`${key}` === "JUN" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".monthMonths=JUN";
        } else {
          weekWeeksStr += "&" + header + ".monthMonths=JUN";
        }
      } else if (`${key}` === "JUL" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".monthMonths=JUL";
        } else {
          weekWeeksStr += "&" + header + ".monthMonths=JUL";
        }
      } else if (`${key}` === "AUG" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".monthMonths=AUG";
        } else {
          weekWeeksStr += "&" + header + ".monthMonths=AUG";
        }
      } else if (`${key}` === "SEP" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".monthMonths=SEP";
        } else {
          weekWeeksStr += "&" + header + ".monthMonths=SEP";
        }
      } else if (`${key}` === "OCT" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".monthMonths=OCT";
        } else {
          weekWeeksStr += "&" + header + ".monthMonths=OCT";
        }
      } else if (`${key}` === "NOV" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".monthMonths=NOV";
        } else {
          weekWeeksStr += "&" + header + ".monthMonths=NOV";
        }
      } else if (`${key}` === "DEC" && `${params[key]}`.toString() === "true") {
        if (weekWeeksStr == "") {
          weekWeeksStr = "?" + header + ".monthMonths=DEC";
        } else {
          weekWeeksStr += "&" + header + ".monthMonths=DEC";
        }
      } else {
        if (`${params[key]}`.toString() === "false") {
          console.log("vvvvvvvvvv");
        } else {
          console.log(`${params[key]}`);
          console.log(`${params[key]}`.toString() === "false");
          newobj[header + "." + `${key}`] = `${params[key]}`;
        }
      }
    });
  }
  if (weekWeeksStr == "") {
    weekWeeksStr = "?" + idsStr;
  } else {
    weekWeeksStr += "&" + idsStr;
  }
  return http.post(`/pages/scheduledTask!editScheduledTask.action` + weekWeeksStr, qs.stringify(newobj));
};

// 删除定时任务
export const deleteScheduledTask = (params: string) => {
  return http.post<String>(`/pages/scheduledTask!deleteScheduledTask.action` + params, qs.stringify({})); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};

// 查询定时任务
export const findScheduledTaskById = (params: string) => {
  return http.post<String>(
    `/pages/scheduledTask!findScheduledTaskById.action?queryDTO.scheduledTaskId=` + params,
    qs.stringify({})
  ); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};

// 上传文件
export const uploadFile = (params: FormData) => {
  return http.post(`/pages/uploadFile!uploadAttr.action?tenantId=yuehaishuiwu_zhengshi`, params);
};

// 分页查询通知模板模板列表
export const findNoticeRulePager = (params: {}, header: string, unhandle: string[]) => {
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      if (unhandle.length > 0) {
        if (unhandle.includes(`${key}`)) {
          newobj[`${key}`] = `${params[key]}`;
        } else {
          newobj[header + "." + `${key}`] = `${params[key]}`;
        }
      } else {
        newobj[header + "." + `${key}`] = `${params[key]}`;
      }
    });
  } else {
    newobj = params;
  }
  return http.post(`/pages/noticeRule!findPager.action`, qs.stringify(newobj));
};

// 检查用户名正确性
export const vaildateUserByLoginName = (params: string) => {
  let newparams = "";
  if (params != "") {
    newparams = params.replaceAll(";", "&userNames=");
  }
  return http.post<String>(`/pages/user!vaildateUserByLoginName.action?userNames=` + newparams, qs.stringify({})); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};

// 保存通知模板
export const addNotices = (params: {}, header: string) => {
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      newobj[header + "." + `${key}`] = `${params[key]}`;
    });
  }
  return http.post<String>(`/pages/noticeRule!addNotices.action`, qs.stringify(newobj)); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};

// 删除通知模板
export const delNoticeRules = (params: string) => {
  return http.post<String>(`/pages/noticeRule!delNoticeRules.action` + params, qs.stringify({})); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};

// 通过id查询通知模板
export const findByFileNameNew = (params: string) => {
  return http.post<String>(`/pages/noticeRule!findByFileNameNew.action?noticeRuleDTO.noticeRuleId=` + params, qs.stringify({})); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};

// 编辑通知模板
export const editNotice = (params: {}, header: string) => {
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      newobj[header + "." + `${key}`] = `${params[key]}`;
    });
  }
  return http.post<String>(`/pages/noticeRule!editNotice.action`, qs.stringify(newobj)); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};

// 查询面板配置
export const findallViewAndUserViewTwo = (params: string) => {
  return http.post<String>(
    `/pages/view!findallViewAndUserViewTwo.action?queryDTO.customType=1&queryDTO.userName=` + params,
    qs.stringify({})
  ); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};

// 查询常规视图
export const findAllSystemView = () => {
  return http.post<String>(`/pages/view!findAllSystemView.action`, qs.stringify({})); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};
// 查询过滤视图
export const findCustomFilter = (params: string, filterCategory: string) => {
  if (filterCategory != "") {
    filterCategory = "&queryDTO.filterCategory=" + filterCategory;
  }
  return http.post<String>(
    `/pages/filter!findCustomFilter.action?queryDTO.userName=` + params + filterCategory,
    qs.stringify({})
  ); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};

// 更新自定义面板行宽度
export const updateRowsWidth = (params: {}, header: string) => {
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      newobj[header + "." + `${key}`] = `${params[key]}`;
    });
  }
  return http.post<String>(`/pages/rowsWidth!updateRowsWidth.action`, qs.stringify(newobj)); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};

// 更新自定义面板视图
export const updateUserCustomView = (params: {}, header: string) => {
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      newobj[header + "." + `${key}`] = `${params[key]}`;
    });
  }
  return http.post<String>(`/pages/userCustom!updateUserCustomView.action`, qs.stringify(newobj)); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};

// 查询报表视图
export const findBaseReport = () => {
  return http.post<String>(`/pages/reportModuleAction!findBaseReport.action`, qs.stringify({})); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};

// 查询单项分组报表视图
export const sgreportFindPager = () => {
  return http.post<String>(`/pages/sgreport!findPager.action`, qs.stringify({})); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};

// 查询多项分组报表视图
export const mutilreportFindPager = () => {
  return http.post<String>(`/pages/mutilreport!findPager.action`, qs.stringify({})); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};

// kpi报表视图
export const kpireportFindPager = () => {
  return http.post<String>(`/pages/kpireport!findPager.action`, qs.stringify({})); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};

// 交叉报表视图
export const crossreportFindPager = () => {
  return http.post<String>(`/pages/crossreport!findPager.action`, qs.stringify({})); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};

/**
 * @name 查询内容模板
 */
// 查询内容模板
export const findPagerContentTemplate = (params: {}, header: string, unhandle: string[]) => {
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      if (unhandle.length > 0) {
        if (unhandle.includes(`${key}`)) {
          newobj[`${key}`] = `${params[key]}`;
        } else {
          newobj[header + "." + `${key}`] = `${params[key]}`;
        }
      } else {
        newobj[header + "." + `${key}`] = `${params[key]}`;
      }
    });
  } else {
    newobj = params;
  }
  return http.postitsm<string>(`/pages/template!findPager.action`, qs.stringify(newobj));
};

// 编辑内容模板名称
export const editTemplateName = (params: {}, header: string) => {
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      newobj[header + "." + `${key}`] = `${params[key]}`;
    });
  }
  return http.post<String>(`/pages/template!editTemplateName.action`, qs.stringify(newobj)); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};

// 删除内容模板
export const deleteContentTemplate = (params: string) => {
  return http.post<String>(`/pages/template!delTemplate.action` + params, qs.stringify({})); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};

// 保存请求内容模板
export const saveRequestTemplate = (params: {}, header: string, idsStr: string) => {
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      if (`${key}` === "approvalNo") {
        newobj[header + ".piv." + `${key}`] = `${params[key]}`;
      } else if (`${key}`.includes("eav_")) {
        newobj[header + ".attrVals['" + `${key}` + "']"] = `${params[key]}`;
      } else if (`${key}` === "templateType") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "templateName") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "templateId") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "isShowBorder") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "isNewForm") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "serviceDirId") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else {
        newobj[header + "." + `${key}`] = `${params[key]}`;
      }
    });
  }
  // return http.post<ResPage<User.ResUserList>>(PORT1 + `/user/list`, params);
  return http.post("" + `/pages/request!saveRequestTemplate.action` + idsStr, qs.stringify(newobj));
};

// 保存问题内容模板
export const saveProblemTemplate = (params: {}, header: string, idsStr: string, serviceDir: string, kuozhanshuju: {}) => {
  console.log(kuozhanshuju);
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      if (`${key}` === "approvalNo") {
        newobj[header + ".piv." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "templateType") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "templateName") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "templateId") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "isShowBorder") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "isNewForm") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "serviceDirId") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else {
        newobj[header + "." + `${key}`] = `${params[key]}`;
      }
    });
  }
  if (kuozhanshuju != undefined) {
    Object.keys(kuozhanshuju).forEach(key => {
      newobj[header + ".attrVals['" + `${key}` + "']"] = `${kuozhanshuju[key]}`;
    });
  }

  if (idsStr == "") {
    idsStr = "?" + serviceDir;
  } else {
    idsStr += "&" + serviceDir;
  }
  // return http.post<ResPage<User.ResUserList>>(PORT1 + `/user/list`, params);
  return http.post("" + `/pages/problem!saveProblemTemplate.action` + idsStr, qs.stringify(newobj));
};

/**
 * @name 通过ID查询内容模板
 */
// 通过ID查询内容模板
export const findByTemplateId = (params: {}, header: string, unhandle: string[]) => {
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      if (unhandle.length > 0) {
        if (unhandle.includes(`${key}`)) {
          newobj[`${key}`] = `${params[key]}`;
        } else {
          newobj[header + "." + `${key}`] = `${params[key]}`;
        }
      } else {
        newobj[header + "." + `${key}`] = `${params[key]}`;
      }
    });
  } else {
    newobj = params;
  }
  return http.post<string>(`/pages/template!findByTemplateId.action`, qs.stringify(newobj));
};

// 查询资产通过ids
export const findCiByIds = (params: string) => {
  return http.post<String>(`/pages/ci!findByIds.action` + params, qs.stringify({})); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};

// 查询是否存在问题扩展信息
export const findSubCategorysByEvenId = (params: string) => {
  return http.post<String>(`/pages/event!findSubCategorysByEvenId.action?categoryId=` + params, qs.stringify({})); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};
// 查询问题扩展信息
export const findAttributeList = (params: string) => {
  return http.post<String>(`/pages/ci!attributeList.action?eavNo=` + params, qs.stringify({})); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};

// 保存变更内容模板
export const saveChangeTemplate = (params: {}, header: string, idsStr: string, serviceDir: string, kuozhanshuju: {}) => {
  console.log(kuozhanshuju);
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      if (`${key}` === "approvalNo") {
        newobj[header + ".piv." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "templateType") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "templateName") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "templateId") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "isShowBorder") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "isNewForm") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "serviceDirId") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else {
        newobj[header + "." + `${key}`] = `${params[key]}`;
      }
    });
  }
  if (kuozhanshuju != undefined) {
    Object.keys(kuozhanshuju).forEach(key => {
      newobj[header + ".attrVals['" + `${key}` + "']"] = `${kuozhanshuju[key]}`;
    });
  }
  if (idsStr == "") {
    idsStr = "?" + serviceDir;
  } else {
    idsStr += "&" + serviceDir;
  }
  // return http.post<ResPage<User.ResUserList>>(PORT1 + `/user/list`, params);
  return http.post(`/pages/change!saveChangeTemplate.action` + idsStr, qs.stringify(newobj));
};

// 保存资产内容模板
export const saveConfigureItemTemplate = (params: {}, header: string, idsStr: string) => {
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      if (`${key}` === "approvalNo") {
        newobj[header + ".piv." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "templateType") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "templateName") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "templateId") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}`.includes("eav_")) {
        newobj[header + ".attrVals['" + `${key}` + "']"] = `${params[key]}`;
      } else if (`${key}` === "isShowBorder") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "isNewForm") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "serviceDirId") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "categoryNo") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
        newobj[header + "." + `${key}`] = `${params[key]}`;
      } else {
        newobj[header + "." + `${key}`] = `${params[key]}`;
      }
    });
  }

  return http.post(`/pages/ci!saveConfigureItemTemplate.action` + idsStr, qs.stringify(newobj));
};

// 查询自定义表单
export const findFormCustomByCiCategoryNo = (params: string) => {
  return http.post<String>(
    `/pages/formCustom!findFormCustomByCiCategoryNo.action?formCustomDTO.ciCategoryNo=` + params,
    qs.stringify({})
  ); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};

// 保存知识内容模板
export const saveKnowledgeTemplate = (params: {}, header: string, idsStr: string) => {
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      if (`${key}` === "approvalNo") {
        newobj[header + ".piv." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "templateType") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "templateName") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "templateId") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "isShowBorder") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "isNewForm") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "serviceDirId") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "categoryNo") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
        newobj[header + "." + `${key}`] = `${params[key]}`;
      }
      // else if(`${key}` === "content"){
      // 		 newobj[`${key}`] = `${params[key]}`;
      // }
      else {
        newobj[header + "." + `${key}`] = `${params[key]}`;
      }
    });
  }

  return http.post(`/pages/knowledgeInfo!saveKnowledgeTemplate.action` + idsStr, qs.stringify(newobj));
};

// 查询自定义表单
export const findPagerFormCustom = (params: {}, header: string, unhandle: string[]) => {
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      if (unhandle.length > 0) {
        if (unhandle.includes(`${key}`)) {
          newobj[`${key}`] = `${params[key]}`;
        } else {
          newobj[header + "." + `${key}`] = `${params[key]}`;
        }
      } else {
        newobj[header + "." + `${key}`] = `${params[key]}`;
      }
    });
  } else {
    newobj = params;
  }
  return http.post<string>(`/pages/formCustom!findPagerFormCustom.action`, qs.stringify(newobj));
};

// 删除自定义表单
export const deleteFormCustom = (params: string) => {
  return http.post<String>(`/pages/formCustom!deleteFormCustom.action` + params, qs.stringify({})); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};

// 查询自定义eav
export const findEavEntity = () => {
  return http.post<String>(`/pages/eav!findEavEntity.action?rows=10000`, qs.stringify({})); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};

// 查询自定义表单是否存在
export const isFormCustomNameExisted = (params: {}, header: string) => {
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      newobj[header + "." + `${key}`] = `${params[key]}`;
    });
  } else {
    newobj = params;
  }
  return http.post<string>(`/pages/formCustom!isFormCustomNameExisted.action`, qs.stringify(newobj));
};

// 查询自定义表单
export const findFormCustomById = (params: string) => {
  return http.post<String>(`/pages/formCustom!findFormCustomById.action?formCustomId=` + params, qs.stringify({})); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};

// 查询自定义字段
export const findAttributesByEavNo = (params: string) => {
  return http.post<String>(`/pages/attrs!findAttributesByEavNo.action?attrsQueryDTO.eavNo=` + params, qs.stringify({})); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};

// 保存请求 自定义表单
export const saveFormCustom = (params: {}, header: string, str: string) => {
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      newobj[header + "." + `${key}`] = `${params[key]}`;
    });
  } else {
    newobj = params;
  }
  return http.post<string>(`/pages/formCustom!saveFormCustom.action` + str, qs.stringify(newobj));
};

// // 查询自所有自定义表单
// export const findSimilarFormCustom = () => {
//   return http.post<String>(`/pages/formCustom!findSimilarFormCustom.action` , qs.stringify({})); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
// };

// 查询自所有自定义表单
export const findSimilarFormCustom = (params: {}, header: string) => {
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      newobj[header + "." + `${key}`] = `${params[key]}`;
    });
  } else {
    newobj = params;
  }
  return http.post<string>(`/pages/formCustom!findSimilarFormCustom.action`, qs.stringify(newobj));
};

/**
 * @name 查询自定义字段
 */
// 查询自定义字段
export const findattrs = (params: {}, header: string, unhandle: string[], idsStr: string) => {
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      if (unhandle.length > 0) {
        if (unhandle.includes(`${key}`)) {
          newobj[`${key}`] = `${params[key]}`;
        } else {
          newobj[header + "." + `${key}`] = `${params[key]}`;
        }
      } else {
        newobj[header + "." + `${key}`] = `${params[key]}`;
      }
    });
  } else {
    newobj = params;
  }
  return http.post(`/pages/attrs!find.action` + idsStr, qs.stringify(newobj));
};

/**
 * @name 保存自定义字段选项卡
 */
// 保存自定义字段选项卡
export const saveFormCustomTabs = (params: {}, header: string, unhandle: string[], idsStr: string) => {
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      if (unhandle.length > 0) {
        if (unhandle.includes(`${key}`)) {
          newobj[`${key}`] = `${params[key]}`;
        } else {
          newobj[header + "." + `${key}`] = `${params[key]}`;
        }
      } else {
        newobj[header + "." + `${key}`] = `${params[key]}`;
      }
    });
  } else {
    newobj = params;
  }
  return http.post(`/pages/formCustomTabs!saveFormCustomTabs.action` + idsStr, qs.stringify(newobj));
};

/**
 * @name 编辑自定义字段选项卡
 */
// 编辑自定义字段选项卡
export const updateFormCustomTabs = (params: {}, header: string, unhandle: string[], idsStr: string) => {
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      if (unhandle.length > 0) {
        if (unhandle.includes(`${key}`)) {
          newobj[`${key}`] = `${params[key]}`;
        } else {
          newobj[header + "." + `${key}`] = `${params[key]}`;
        }
      } else {
        newobj[header + "." + `${key}`] = `${params[key]}`;
      }
    });
  } else {
    newobj = params;
  }
  return http.post(`/pages/formCustomTabs!updateFormCustomTabs.action` + idsStr, qs.stringify(newobj));
};
